﻿myApp.controller("AccountCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    $scope.UserProfile = {};
    $scope.GetCustomerInfo = function (order_id) {
        $http({ method: "GET", url: $restUrls["getCustomerInfo"], params: {} }).success(function (result) {
            if (result.success == 1) {
                $scope.UserProfile = result.data;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    $scope.GetCustomerInfo();
}]).controller("UserInfoCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {




    //选择省
    $scope.ChooseCountry = function (country) {
        $scope.ProvinceShow = false;
        $scope.CityShow = true;
        $scope.Userinfo.choose_country = country;
        $http({ method: "GET", url: $restUrls["getZone"], params: { country_id: country.country_id } }).success(function (result) {
            if (result.success == 1) {
                $scope.ZoneList = result.data;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    //选择市
    $scope.ChooseZone = function (zone) {
        $scope.ProvinceShow = false;
        $scope.CityShow = false;
        $scope.addressshow = false;
        $scope.Userinfo.choose_zone = zone;
        $scope.Userinfo.addressformat = $scope.Userinfo.choose_country.name + $scope.Userinfo.choose_zone.name;
    }

    $scope.GetCustomerInfo = function () {
        $http({ method: "GET", url: $restUrls["getCustomerInfo"], params: {} }).success(function (result) {
            if (result.success == 1) {
                var UserProfile = result.data;
                $scope.Userinfo.lastname = UserProfile.lastname;
                $scope.Userinfo.telephone = UserProfile.telephone;
                $scope.Userinfo.birthday = UserProfile.birthday;
                for (var i = 0; i < $scope.Grades.length; i++) {
                    if ($scope.Grades[i].time == UserProfile.grade) {
                        $scope.Userinfo.choose_grade = $scope.Grades[i];
                    }
                }
                $http({ method: "GET", url: $restUrls["getCountry"], params: {} }).success(function (result) {
                    if (result.success == 1) {
                        $scope.CountryList = result.data;
                        for (var i = 0; i < $scope.CountryList.length; i++) {
                            if ($scope.CountryList[i].country_id == UserProfile.country_id) {
                                $scope.Userinfo.choose_country = $scope.CountryList[i];
                                $scope.Userinfo.addressformat = $scope.Userinfo.choose_country.name;
                            }
                        }
                        $http({ method: "GET", url: $restUrls["getZone"], params: { country_id: UserProfile.country_id } }).success(function (result) {
                            if (result.success == 1) {
                                var ZoneList = result.data;
                                for (var i = 0; i < ZoneList.length; i++) {
                                    if (ZoneList[i].zone_id == UserProfile.zone_id) {
                                        $scope.Userinfo.choose_zone = ZoneList[i];
                                        $scope.Userinfo.addressformat = $scope.Userinfo.addressformat + $scope.Userinfo.choose_zone.name;
                                    }
                                }
                            }
                            if ($scope.Userinfo.addressformat == '' || $scope.Userinfo.lastname == '' || $scope.Userinfo.telephone == '' || $scope.Userinfo.birthday == '' || $scope.Userinfo.grade == '') {
                                one_isaddpoints = true;
                            }
                        })
                    }
                });
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }






    //优学派机器信息
    $scope.HardWare = {};
    $scope.GetCustomerHardWare = function () {
        $http({ method: "GET", url: $restUrls["getCustomerHardWare"], params: {} }).success(function (result) {
            if (result.success == 1) {
                $scope.HardWare = result.data;
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }

   // $scope.GetCustomerHardWare();


}]);